package formbeans;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class NumericForm extends FormBean {

	private String question;
	private String dynetmlAttr;
	private String min;
	private String max;
	
	public String getQuestion() {
		return question;
	}
	public String getDynetmlAttr() {
		return dynetmlAttr;
	}
	public String getMin() {
		return min;
	}
	public String getMax() {
		return max;
	}

	public void setQuestion(String question) {
		this.question = trimAndConvert(question,"<>\"");
	}
	public void setDynetmlAttr(String dynetmlAttr) {
		this.dynetmlAttr = trimAndConvert(dynetmlAttr, "<>\"");
	}
	public void setMin(String min) {
		this.min = trimAndConvert(min, "<>\"");
	}
	public void setMax(String max) {
		this.max = trimAndConvert(max, "<>\"");
	}
	
	public List<String> checkNumericFormErrors(){
		List<String> errors = new ArrayList<String>();
		
		if(question == null || question.length() == 0){
			errors.add("Please enter a question");
		}
		if(dynetmlAttr == null || dynetmlAttr.length() == 0){
			errors.add("Please enter description for \"dynetml attribute identifier\"");
		}
		try {
			int imin = Integer.parseInt(min);
			int imax = Integer.parseInt(max);
			if (imin > imax)
				errors.add("Minimum should be less than or equal to Maximum value.");
		} catch (NumberFormatException e) {
			errors.add("Please enter valid number.");
		}
		
		return errors;
	}
}